package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.egg.ylt.R;
import com.egg.ylt.adapter.ADA_LookBigPictrue;
import com.egg.ylt.pojo.DiaryPhotoEntity;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ACT_LookBigPicture extends AppCompatActivity {

    @BindView(R.id.big_recycler)
    RecyclerView bigRecycler;
    @BindView(R.id.rl_cancel_check)
    RelativeLayout rlCancel;
    @BindView(R.id.big_back)
    ImageView bigBack;

    private int mPosition;

    private ADA_LookBigPictrue mImgAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_look_big_picture);
        ButterKnife.bind(this);

        //得到图片集合
        DiaryPhotoEntity.ListBean listBean = (DiaryPhotoEntity.ListBean)getIntent().getBundleExtra("bundle").getSerializable("listBean");
        mPosition = getIntent().getIntExtra("position", 0);
        //初始化recyclerview
        initView(listBean.getDateList());

//        rlCancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });

        bigBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView(List<DiaryPhotoEntity.ListBean.DateListBean> list) {
        //设置布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        bigRecycler.setLayoutManager(layoutManager);

        //适配器
        mImgAdapter = new ADA_LookBigPictrue(this);
        bigRecycler.setAdapter(mImgAdapter);
        if (mPosition < list.size()){
            bigRecycler.scrollToPosition(mPosition);
        }

        //设置数据
        mImgAdapter.setDataList(list);
    }
}
